package models.send;

import models.System.Headline.code;
import models.Models.Email;
import models.Models.HTMLEmail;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;
import play.Logger;
import play.libs.Mail;
import play.mvc.Mailer;



/**
 * Created by Administrator on 2018-06-23.
 */
public class email extends Mailer   {

    public static void HTMLEmail(HTMLEmail htmlEmail){

        try {

            HtmlEmail email = new HtmlEmail();
            email.addTo(htmlEmail.account);
            email.setFrom(code.SystemUserEmail);
            email.setSubject(htmlEmail.title);
            String cid = email.embed(htmlEmail.url, htmlEmail.ImgTitle);
            Logger.info(cid);
            email.setHtmlMsg(htmlEmail.HTML.toString());
            email.setTextMsg(htmlEmail.TestMsg);
            Mail.send(email);
        } catch (EmailException e) {
            e.printStackTrace();
        }

    }
    public static void MsgEmail(Email emails){
        SimpleEmail email = new SimpleEmail();
        try {

            email.setFrom(code.SystemUserEmail);
            email.addTo(emails.account);
            email.setSubject(emails.title);
            email.setContent(emails.msg,"text/plain; charset=utf-8");
            Mail.send(email);
        } catch (EmailException e) {
            e.printStackTrace();
        }
    }

//    public static void welcome(SystemUserCollection systemUser) {
//        // 邮件主题
//        setSubject("Welcome %s", systemUser.UserName);
//        // 邮件接收者
//        addRecipient(user.email);
//        // 邮件发送者
//        setFrom("Me <me@me.com>");
//        // 添加附件
//        EmailAttachment attachment = new EmailAttachment();
//        attachment.setDescription("A pdf document");
//        attachment.setPath(Play.getFile("rules.pdf").getPath());
//        addAttachment(attachment);
//        // 以模板推送，渲染邮件
//        send(user);
//    }
}




